home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlib.zip / STRNRPT.C < prev    next >
Text File  |  1993-01-04  |  1KB  |  35 lines

  1.  
  2. /*  File   : strnrpt.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 20 April 1984
  5.     Defines: strnrpt()
  6.  
  7.     strnrpt(dst, n, src, k) "RePeaTs" the string src into dst  k  times,
  8.     but  will  truncate  the  result at n characters if necessary.  E.g.
  9.     strnrpt(dst, 7, "hack ", 2) will move "hack ha" to dst  WITHOUT  the
  10.     closing  NUL.   The  result  is  the number of characters moved, not
  11.     counting the closing NUL.  Equivalent to strrpt-ing into an infinite
  12.     buffer and then strnmov-ing the result.
  13. */
  14.  
  15. #include "strings.h"
  16.  
  17. int strnrpt(dst, n, src, k)
  18.     register char *dst;
  19.     register int n;
  20.     char *src;
  21.     int k;
  22.     {
  23.         char *save;
  24.  
  25.         for (save = dst; --k >= 0; dst--) {
  26.             register char *p;
  27.             for (p = src; ; ) {
  28.                 if (--n < 0) return dst-save;
  29.                 if (!(*dst++ = *p++)) break;
  30.             }
  31.         }
  32.         return dst-save;
  33.     }
  34.  
  35.